6/10/23
Email:dr.myominnoo@gmail.com
Twitter: @dr_myominnoo
GitHub: https://github.com/myominnoo
Shiny things!R for Researchers monthly events for learning and networking at UoM, Winnipeg. It’s a good environment for practicing organizing tutorials.Myanmar R User Group online weekly events: organize and facilite R-related tutorials.Messy codes
User authentication - not standardized (not modular)
Sign-up feature - email and mongoDB credentials are hard-coded!!!
No password recovery function for users (me and my wife!)
Buggy
shinyauthr and shinymanager - very useful packages, yet no sign-up or password recovery functionalities
Bias: Other packages with similar functionalities might exist!
Or Making my life more complicated!
Created in draw.io
Vignette: https://myominnoo.github.io/shinyAuthX
# A tibble: 3 × 6
date_created username password name email permissions
<dttm> <chr> <chr> <chr> <chr> <chr>
1 2023-06-08 01:49:29 admin $7$C6..../....rLHXP8EXaC… Admin admi… admin
2 2023-06-08 01:49:29 user1 $7$C6..../....bOBbF4NeEv… User… user… standard
3 2023-06-08 01:49:29 user2 $7$C6..../....gggTNcZikU… User… user… standard
ui <- fluidPage(
# add signout button UI
div(class = "pull-right", signoutUI(id = "signout")),
# add signin panel UI function without signup or password recovery panel
signinUI(id = "signin", .add_forgotpw = FALSE, .add_btn_signup = FALSE),
# setup output to show user info after signin
verbatimTextOutput("user_data")
)server <- function(input, output, session) {
# call the signout module with reactive trigger to hide/show
signout_init <- signoutServer(
id = "signout",
active = reactive(credentials()$user_auth)
)
# call signin module supplying data frame,
credentials <- signinServer(
id = "signin",
users_db = users_base,
sodium_hashed = TRUE,
reload_on_signout = FALSE,
signout = reactive(signout_init())
)
output$user_data <- renderPrint({
# use req to only render results when credentials()$user_auth is TRUE
req(credentials()$user_auth)
str(credentials())
})
}library(mongolite)
## default mongodb database server for testing: works only with `mtcars`
con <- mongo("mtcars", url = "mongodb+srv://readwrite:test@cluster0-84vdt.mongodb.net/test")
## remove any existing rows
con$drop()
## check
con$count()
# add users_base to con
shinyAuthX::create_dummy_users() |>
con$insert()
## check again
con$count()
## retrieve data
con$find(fields = '{}')con to users_db argsui <- fluidPage(
# add signout button UI
div(class = "pull-right", signoutUI(id = "signout")),
# add signin panel UI function with signup panel
signinUI(id = "signin", .add_forgotpw = TRUE, .add_btn_signup = TRUE),
# add signup panel
signupUI("signup"),
# add password-reset panel
forgotpwUI("pw-reset"),
# setup output to show user info after signin
verbatimTextOutput("user_data")
)credentials & con to the other parts!server <- function(input, output, session) {
# call the signout module with reactive trigger to hide/show
signout_init <- signoutServer(
id = "signout",
active = reactive(credentials()$user_auth)
)
# call signin module supplying data frame,
credentials <- signinServer(
id = "signin",
users_db = con$find('{}'), ## add mongodb connection instead of tibble
sodium_hashed = TRUE,
reload_on_signout = FALSE,
signout = reactive(signout_init())
)
# call signup module supplying credentials() reactive and mongodb
signupServer(
id = "signup", credentials = credentials, mongodb = con
)
# call password-reset module supplying credentials() reactive and mongodb
forgotpwServer(
id = "pw-reset", credentials = credentials, mongodb = con
)
output$user_data <- renderPrint({
# use req to only render results when credentials()$user_auth is TRUE
req(credentials()$user_auth)
str(credentials())
})
}blastula package - Compose emails: compose_email() - Send emails: smtp_send() - credential file: creds_file()
template <- shinyAuthX::email_template(
creds_file = blastula::creds_file("path/outlook_creds"),
from = "user@email.com"
)
## changes to server
server <- function(input, output, session) {
## other codes here
# call signup module supplying credentials() reactive and mongodb
signupServer(
id = "signup", credentials = credentials, mongodb = con, email = template
)
# call password-reset module supplying credentials() reactive and mongodb
forgotpwServer(
id = "pw-reset", credentials = credentials, mongodb = con, email = template
)
}shinipsum and fakirsemantic.dashboard, shiny.fluent, and others - compatibility issuesshinydashboard to integrate authenticationbs4Dash for app UIshinyAuthX - R4DS Project-Club 2023